﻿using Ldt.DataEngine.DataFlowParse.Model;
using Ldt.DataEngine.RuleAssemble;
using LdtDataEngin.ModuleDetail.BaseModule.PersonnelBase;
using LdtJudge.DataEngine.Common;
using LdtJudge.DataEngine.Common.DateAssemble;
using LdtJudge.DataEngine.Common.XmlUtility;
using LdtJudge.DataEngine.Data;
using LdtJudge.DataEngine.DataBaseStores;
using LdtJudge.DataEngine.Model.DataModel.DataParseStorage;
using LdtJudge.DataEngine.Model.DataModel.SysCommon;
using LdtJudge.DataEngine.Model.ElmentModel;
using LdtJudge.DataEngine.Model.Personnel;
using LdtJudge.DataEngine.Model.XMLConfigModel.ConfigModel;
using LdtJudge.DataEngine.Model.XMLConfigModel.DataStores;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using LdtJudge.DataEngine.DataBaseStores.Cached;
using Newtonsoft.Json.Linq;

namespace LdtDataEngin.ModuleDetail.BaseModule
{
    /// <summary>
    /// 文书要素提取通用抽象类
    /// Class FactElementBaseClass.
    /// </summary>
    public abstract class FactElementBaseClass
    {
        #region 基础信息加载

        /// <summary>
        /// 上下文数据
        /// </summary>
        public DataContext _dataContext;

        /// <summary>
        /// 配置信息
        /// </summary>
        private ElementConfig ElementConfig = new ElementConfig();

        /// <summary>
        /// 案由信息
        /// </summary>
        public List<CaseCauseModel> casecauseList { get; set; }

        /// <summary>
        /// 逻辑段分段编号将诉请内容排除
        /// </summary>
        public List<string> suitinfocode = new List<string>() { "" };

        /// <summary>
        /// 无争议要素段落
        /// </summary>
        public List<string> suitin = new List<string>() { "" };

        /// <summary>
        /// 节点提取原文内容
        /// </summary>
        public List<NodeModel> OriginalTextNodeList = new List<NodeModel>();

        /// <summary>
        /// 结果段落集合
        /// </summary>
        public List<string> resultParagraphList = new List<string>();

        /// <summary>
        /// 结果要素诉讼地位集合
        /// </summary>
        public List<string> resultPersonnelList = new List<string>();

        /// <summary>
        ///案件的ID
        /// </summary>
        public string CaseID { get; set; }

        /// <summary>
        /// 进行获取到人员的原文数据
        /// </summary>
        public Dictionary<PersonElementEntity, string> GroupParseTextDic { get; set; }

        /// <summary>
        /// 人员信息表结合
        /// </summary>
        public List<ElementSpokeName> spokenamelist { get; set; }

        /// <summary>
        /// 要素提取完毕调用委托
        /// </summary>
        /// <param name="extype">要素提取类型</param>
        /// <param name="ExtModel">当前内容提取后的结果</param>
        /// <param name="ListMessage">消息集合</param>
        /// <param name="Person">人员对象.</param>
        public delegate void OnExtractComplete(ExtractType extype, List<NodeModel> ExtModel, IList<string> ListMessage,
            PersonElementEntity Person);

        /// <summary>
        /// 要素提取入口1
        /// </summary>
        /// <param name="onExtract">委托回调数据</param>
        /// <param name="nodeModelList">数据传递对象</param>
        /// <returns></returns>
        public abstract XmlNode ExtElementXmlParse(OnExtractComplete onExtract, NodeModelList nodeModelList);

        /// <summary>
        /// 消息集合
        /// </summary>
        public List<string> messagelist { get; set; }

        /// <summary>
        /// 案由实体
        /// </summary>
        public CaseCauseModel causeSys { get; set; }

        /// <summary>
        /// cofigin配置
        /// </summary>
        public Dictionary<string, ElementConfigModel> Diccofig { get; set; }

        /// <summary>
        /// 事实要素节点机器学习配置
        /// </summary>
        public string FactNodelMLConfig { get; set; }

        #endregion

        #region 基础查询方法

        /// <summary>
        /// 获取案由对象
        /// </summary>
        /// <param name="cc_id"></param>
        /// <param name="casetype"></param>
        /// <returns></returns>
        public CaseCauseModel GetCaseCauseModel(string cc_id)
        {
            return ElementConfig.GetCaseCauseModel(cc_id);
        }

        /// <summary>
        /// 根据案由ID获取所有需要进行提取的要素节点
        /// </summary>
        /// <param name="casecauseID">案由ID</param>
        /// <returns></returns>
        public IList<CaseCauseModel> GetMSYS_CaseCausesList(string casecauseID)
        {
            return ElementConfig.GetAllFact_ElementList(casecauseID);
        }

        /// <summary>
        /// 根据案由ID获取所有要素需要转字典
        /// 或调用参数方法集合
        /// </summary>
        /// <param name="casecauseID">案由ID</param>
        /// <returns></returns>
        public Dictionary<string, ElementConfigModel> GetElementConfig(string casecauseID)
        {
            return ElementConfig.InitElementParamter(casecauseID);
        }

        /// <summary>
        /// 返回原始文本提取的结果值。
        /// </summary>
        /// <param name="CC_ID">节点ID</param>
        /// <param name="isFirstLevel">是否顶层</param>
        /// <param name="OriginalText">原文</param>
        /// <param name="Paragraph">逻辑段集合</param>
        /// <param name="ExpressSourceWhere">条件对象</param>
        /// <returns>提取结果列表</returns>
        protected Dictionary<string, List<string>> FactExtract_OriginalText(string CC_ID, bool isFirstLevel, string OriginalText,
            Dictionary<string, List<string>> Paragraph, CommElementRegexCode ExpressSourceWhere, out bool isML)
        {
            isML = false;
            Dictionary<string, List<string>> reList = new Dictionary<string, List<string>>();
            if (ExpressSourceWhere != null)
            {
                IList<MSYS_Express_Source> MSourceArr = null;
                if (_dataContext.DataLayerAns.dicTable.ContainsKey("MSYS_Express_Source"))
                {
                    // MSourceArr = (List<MSYS_Express_Source>)_dataContext.DataLayerAns.dicTable["MSYS_Express_Source"];
                    //
                    // if (!string.IsNullOrWhiteSpace(CC_ID))
                    // {
                    //     MSourceArr = MSourceArr.Where(a => a.CC_ID == CC_ID).ToList();
                    // }
                    // if (!string.IsNullOrWhiteSpace(ExpressSourceWhere.SourceCode))
                    // {
                    //     MSourceArr = MSourceArr.Where(a => a.Source_ID.Contains(ExpressSourceWhere.SourceCode)).ToList();
                    // }
                    //
                    // if (!string.IsNullOrWhiteSpace(ExpressSourceWhere.PargarphCode))
                    // {
                    //     MSourceArr = MSourceArr.Where(a => a.Source_ParagraphID.ToLower()== ExpressSourceWhere.PargarphCode.ToLower()).ToList();
                    // }
                    //
                    // if (ExpressSourceWhere.TextType > 0)
                    // {
                    //     MSourceArr = MSourceArr.Where(a => a.Source_texttype == ExpressSourceWhere.TextType.ToString()).ToList();
                    // }
                    // MSourceArr = MSourceArr.Where(a => a.Am_code == ((int)ExpressSourceWhere.Purpose).ToString()).ToList();

                    var initial = MsysExpressSourceCached.Copy_Hash(MsysExpressSourceCached.EsIdSt);

                    if (!string.IsNullOrWhiteSpace(CC_ID))
                    {
                        initial = MsysExpressSourceCached.HashSet_String_Intersection(initial,
                            MsysExpressSourceCached.CcIdHt[CC_ID]);
                    }

                    if (!string.IsNullOrWhiteSpace(ExpressSourceWhere.PargarphCode))
                    {
                        initial = MsysExpressSourceCached.HashSet_String_Intersection(initial,
                            MsysExpressSourceCached.SourceParagraphIdHt[ExpressSourceWhere.PargarphCode.ToLower()]);
                    }

                    if (!string.IsNullOrWhiteSpace(ExpressSourceWhere.SourceCode))
                    {
                        initial = MsysExpressSourceCached.HashSet_String_Intersection(initial,
                            MsysExpressSourceCached.SourceIdHt[ExpressSourceWhere.SourceCode]);
                    }

                    if (ExpressSourceWhere.TextType > 0)
                    {
                        initial = MsysExpressSourceCached.HashSet_String_Intersection(initial,
                            MsysExpressSourceCached.SourceTextTypeHt[ExpressSourceWhere.TextType.ToString()]);
                    }

                    initial = MsysExpressSourceCached.HashSet_String_Intersection(initial,
                        MsysExpressSourceCached.AmCodeHt[((int)ExpressSourceWhere.Purpose).ToString()]);

                    MSourceArr = MsysExpressSourceCached.Restore(initial);
                }
                else
                {
                    string sqlwhere = "  1=1 ";
                    if (!string.IsNullOrWhiteSpace(CC_ID))
                    {
                        //节点的ID
                        sqlwhere += " and CC_ID = '" + CC_ID + "' ";
                    }

                    if (!string.IsNullOrWhiteSpace(ExpressSourceWhere.SourceCode))
                    {
                        //文书编号
                        sqlwhere += " and Source_ID like '%" + ExpressSourceWhere.SourceCode + "%' ";
                        //sqlwhere += " and Source_ID like '%" + ExpressSourceWhere.SourceCode + "%' ";
                    }

                    if (!string.IsNullOrWhiteSpace(ExpressSourceWhere.PargarphCode))
                    {
                        //逻辑段编号
                        sqlwhere += " and Source_ParagraphID= '" + ExpressSourceWhere.PargarphCode.ToLower() + "'";
                    }

                    if (ExpressSourceWhere.TextType > 0)
                    {
                        //文本类型
                        sqlwhere += " and Source_TextType = " + ExpressSourceWhere.TextType;
                    }

                    //用途
                    sqlwhere += " and AM_Code = '" + (int)ExpressSourceWhere.Purpose + "' ";

                    DALSYS_Express_Source dalRegexSource = new DALSYS_Express_Source();
                    MSourceArr = dalRegexSource.GetListArrayWhere(sqlwhere);
                }

                ///当前规则数据集合，应该只有一条
                if (MSourceArr != null)
                {
                    foreach (MSYS_Express_Source msource in MSourceArr)
                    {
                        if (msource.IsML == 1)
                            isML = true;
                        var content = OriginalText;
                        string paragraphCode = msource.Source_ParagraphID.ToLower();
                        //非首级结点，对父原文做本级结点原文的提取。
                        if (!isFirstLevel)
                        {
                            string rzContent;
                            reList = RuleParseClass.GetParseRegCodeListNew(msource.CC_RegexInfoCode,
                                OriginalText, ExpressSourceWhere.RegexParameter,out rzContent);
                            if(!string.IsNullOrEmpty(rzContent))
                                _dataContext.InteractiveShow.LogShow(rzContent);
                            //IList<string> listemp = tiemreg(msource.CC_RegexInfoCode,
                            //    OriginalText, ExpressSourceWhere.RegexParameter);
                            //if (listemp.Count > 0)
                            //{
                            //    reList.AddRange(listemp);
                            //}
                        }
                        else
                        {
                            if (Paragraph.ContainsKey(paragraphCode))
                            {
                                IList<string> paragList = Paragraph[paragraphCode];
                                foreach (string paragText in paragList)
                                {
                                    string rzContent;
                                    reList = RuleParseClass.GetParseRegCodeListNew(
                                        msource.CC_RegexInfoCode, paragText, ExpressSourceWhere.RegexParameter, out rzContent);
                                    if (!string.IsNullOrEmpty(rzContent))
                                        _dataContext.InteractiveShow.LogShow(rzContent);
                                    //IList<string> extractValue = tiemreg(msource.CC_RegexInfoCode, paragText, ExpressSourceWhere.RegexParameter);
                                    //foreach (string nvalue in extractValue)
                                    //{
                                    //    reList.Add(nvalue);
                                    //}
                                }
                            }
                        }

                        ///正则编号
                        ExpressSourceWhere.RegexCode = msource.CC_RegexInfoCode;
                    }

                    //reList = reList.Distinct().ToList();
                }
            }

            return reList;
        }

        public IList<string> tiemreg(string regcode, string text, string tj)
        {
            List<string> list = new List<string>();
            Stopwatch swtext = new Stopwatch();
            swtext.Start();
            list = RuleParseClass.GetParseRegCodeList(regcode, text, tj);
            swtext.Stop();
            if (swtext.ElapsedMilliseconds > 3000)
            {
                string regParam = !string.IsNullOrWhiteSpace(tj) ? $"正则条件：{tj}," : string.Empty;
                string content = $"正则编号为【{regcode}】的正则执行时长{swtext.ElapsedMilliseconds}毫秒,{regParam}原文：{text}";
                _dataContext.InteractiveShow.LogShow(content);
                //WriteLog("分析总时长" + swtext.ElapsedMilliseconds.ToString("0.00") + ",正则编号:" + regcode + "原文：" + text + "正则条件:" + tj, "\\log\\log.txt", false);
            }

            return list;
        }
        public static void WriteLog(string content, string fileRelativePath, bool tagDateTime)
        {

            string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\" + fileRelativePath;
            string filefolder = AppDomain.CurrentDomain.BaseDirectory + "\\Log";
            if (!Directory.Exists(filefolder))
                Directory.CreateDirectory(filefolder);

            if (!File.Exists(filePath))
                File.Create(filePath).Close();

            StreamWriter sw = new StreamWriter(filePath, true);
            if (tagDateTime)
            {
                sw.WriteLine("\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "----------------------------");
            }
            sw.WriteLine(content);
            sw.WriteLine("\r\n");
            sw.Close();

        }
        #endregion

        #region 要素去重

        protected XmlDocument EscapeNodeIndexAndBlank(XmlDocument docxml)
        {
            ///去除空节点
            docxml = EscapeBlank(docxml);
            return docxml;
        }

        /// <summary>
        /// 去除xml中的空节点
        /// </summary>//*[not(attribute::*) and not (child::*)]
        /// <param name="second">待去除xml</param>
        /// <returns>取出后的结果</returns>
        protected XmlDocument EscapeBlank(XmlDocument second)
        {
            XmlNodeList blanks = second.SelectNodes("//*[ not (child::*)]"); //取无属性 无子节点的节点
            while (blanks.Count > 0)
            {
                bool flag = true;

                foreach (XmlNode node in blanks)
                {
                    if (node.Attributes["id"] != null && node.Attributes.Count == 1)
                    {
                        if (node.ParentNode != null && node.ParentNode.ParentNode != null)
                        {
                            node.ParentNode.RemoveChild(node);
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                    else
                    {
                        flag = false;
                    }
                }

                blanks = second.SelectNodes("//*[ not (child::*)]"); //递归查询

                if (!flag)
                {
                    break;
                }
            }

            return second;
        }

        #endregion


        /// <summary>
        /// 根据上级父原文循环节点
        /// </summary>
        /// <param name="nodeM">父级节点及配置数据</param>
        /// <param name="sys_CaseCause">案由数据</param>
        /// <param name="listNodeModel">NodeModel结果集合</param>
        /// <param name="OriginalText">原文</param>
        /// <param name="Paragraph">段落数据</param>
        /// <param name="ExpressSourceWhere">要素提取规则配置</param>
        public void LoadeNodeModel(NodeModel nodeM, CaseCauseModel sys_CaseCause, List<NodeModel> listNodeModel,
            string OriginalText, Dictionary<string, List<string>> Paragraph, CommElementRegexCode ExpressSourceWhere)
        {
            try
            {
                bool isFirstLevel = false;
                if (nodeM == null)
                    isFirstLevel = true;
                //执行节点提取前，进行先清空正则编号
                ExpressSourceWhere.RegexCode = "";

                var configmodel = Diccofig.ContainsKey(sys_CaseCause.XmlPath) ? Diccofig[sys_CaseCause.XmlPath] : null;
                if (configmodel != null && !string.IsNullOrEmpty(configmodel.parentnode))
                {
                    ExpressSourceWhere.RegexParameter = "sp_name:" + listNodeModel
                        .FirstOrDefault(a => a.ParentGuidID == nodeM.GuidID && a.NodeName == configmodel.parentnode)?
                        .ExtOriginalText[0];
                }

                messagelist.Add("\r\n 当前提取的要素节点为《" + sys_CaseCause.CC_Name + "》提取原文为：\r\n" + OriginalText);
                bool isML = false;
                Stopwatch swtext = new Stopwatch();
                swtext.Start();
                Dictionary<string, List<string>> listvalueNew = FactExtract_OriginalText(sys_CaseCause.CC_ID, isFirstLevel, OriginalText,
                    Paragraph, ExpressSourceWhere, out isML);
                swtext.Stop();
                List<string> listvalue = new List<string>();
                if (listvalueNew.Count > 0)
                {
                    listvalue = listvalueNew.ContainsKey("reg") ? listvalueNew["reg"] : listvalueNew["Ai"];
                }
                if (isML && !string.IsNullOrWhiteSpace(FactNodelMLConfig))
                {
                    //通过机器学习提取
                    FactNodeMachLearnClass mlExtract = new FactNodeMachLearnClass() { _dataContext = _dataContext, casecauseList = casecauseList, Diccofig = Diccofig, uieConfig = FactNodelMLConfig };

                    var mlNodeModels = mlExtract.NodeExtractThroughML(OriginalText, nodeM.GuidID, sys_CaseCause.XmlPath, listvalue);
                    if (mlNodeModels != null)
                        listNodeModel.AddRange(mlNodeModels);
                }
                else
                {
                    string value = string.Empty;
                    //通过正则提取
                    #region 节点原文提取值
                    if (configmodel != null && configmodel.checkType == "check")
                    {
                        value = string.Join("\r", listvalue);
                        listvalue = new List<string>();
                        listvalue.Add(value);
                        OriginalText = value;
                    }
                    NodeModel nodeModel = new NodeModel();
                    nodeModel.ModelType = 1;
                    nodeModel.GuidID = Snowflake.Instance().GetId().ToString();
                    nodeModel.NodeID = sys_CaseCause.CC_ID;
                    nodeModel.ParentGuidID = nodeM == null ? sys_CaseCause.CC_ParentID : nodeM.GuidID;
                    nodeModel.NodePath = sys_CaseCause.XmlPath;
                    nodeModel.NodeName = sys_CaseCause.CC_Name + "_OriginalText";
                    nodeModel.OriginalText = OriginalText;
                    nodeModel.ExtOriginalText = listvalue;
                    nodeModel.ExtValue = listvalue;
                    if (listvalue != null && listvalue.Count > 0)
                    {
                        nodeModel.IsNullExtOriginalText = true;
                    }
                    nodeModel.ElementConfigModel =
                        Diccofig.ContainsKey(nodeModel.NodePath) ? Diccofig[nodeModel.NodePath] : null;
                    nodeModel.ElementCommWhere = (CommElementRegexCode)ExpressSourceWhere.Clone();

                    OriginalTextNodeList.Add(nodeModel);
                    #endregion
                    int i = 0;
                    foreach (string extvalue in listvalue)
                    {
                        i++;
                        messagelist.Add("\r\n当前提取的要素节点为《" + sys_CaseCause.CC_Name + "》提取后原文：\r\n  结果集【" + (i) + "】" +
                                        extvalue);
                        NodeModel nodeModelT = (NodeModel)nodeModel.Clone();
                        nodeModelT.GuidID = Snowflake.Instance().GetId().ToString();
                        ///赋值节点的原文内容ID
                        nodeModelT.OriginalGuidID = nodeModel.GuidID;
                        nodeModelT.NodeName = sys_CaseCause.CC_Name;
                        nodeModelT.ExtOriginalText = new List<string>() { extvalue };
                        nodeModelT.IsNullExtOriginalText = true;
                        if (listvalueNew.ContainsKey("rerule") && !string.IsNullOrEmpty(extvalue))
                        {
                            if (listvalueNew["rerule"][0] != null)
                            {
                                string jsonString = listvalueNew["rerule"][0].ToString();
                                if (!string.IsNullOrWhiteSpace(jsonString)&&JsonHelper.IsRightJson(jsonString))
                                {
                                    JArray ja = (JArray)JsonConvert.DeserializeObject(jsonString);
                                    foreach (JObject item in ja)
                                    {
                                        if (item["Vlaue"].ToString().Equals(extvalue))
                                        {
                                            string index = item["Index"].ToString();
                                            string length = item["Length"].ToString();
                                            if (!string.IsNullOrEmpty(index))
                                                nodeModelT.OriginalLocation = index;
                                            if (!string.IsNullOrEmpty(length))
                                                nodeModelT.OriginalLocationLen = length;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        //获取当前节点的配置信息
                        List<NodeModel> listmodel = ImplementConfig(nodeModelT, listNodeModel);

                        if (nodeModelT.ElementConfigModel != null && nodeModelT.ElementConfigModel.isPersonNode == 1 &&
                            nodeModelT.IsNullExtOriginalText == true)
                        {
                            ////如果存在配置，进行人员节点的内容提取
                            ElementConfigModel elementConfigModel = nodeModelT.ElementConfigModel;
                            if (elementConfigModel.isPersonNode == 1)
                            {
                                ////当前节点为人员提取节点
                                NodeAttributesPersonnel(nodeModelT, sys_CaseCause.CC_ID, listNodeModel, extvalue, Paragraph,
                                    ExpressSourceWhere);
                            }
                        }
                        else
                        {
                            ////普通节点属性内容的提取
                            listNodeModel.Add(nodeModelT);
                            foreach (NodeModel nodem in listmodel)
                            {
                                ///进行属性内容的提取
                                LoadeNodeAttributes(nodem, sys_CaseCause.CC_ID, listNodeModel, extvalue, Paragraph,
                                    ExpressSourceWhere);
                                List<CaseCauseModel> list = casecauseList
                                    .Where(a => a.CC_ParentID == sys_CaseCause.CC_ID && a.CC_NodeType == 11).ToList();
                                if (list != null)
                                {
                                    ///遍历下级节点内容
                                    foreach (CaseCauseModel casecause in list)
                                    {
                                        LoadeNodeModel(nodem, casecause, listNodeModel, extvalue, Paragraph,
                                            ExpressSourceWhere);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _dataContext.InteractiveShow.LogShow("要素节点信息提取提取错误，" + ex.ToString(), LogMessageType.Error);
            }
        }

        /// <summary>
        /// 人员节点数据提取
        /// </summary>
        /// <param name="nodeMo"></param>
        /// <param name="NodeCC_ID"></param>
        /// <param name="listNodeModel"></param>
        /// <param name="OriginalText"></param>
        /// <param name="Paragraph"></param>
        /// <param name="ExpressSourceWhere"></param>
        public void NodeAttributesPersonnel(NodeModel nodeMo, string NodeCC_ID, List<NodeModel> listNodeModel,
            string OriginalText, Dictionary<string, List<string>> Paragraph, CommElementRegexCode ExpressSourceWhere)
        {
            PersonnelAnalysisBase personnelAnalysis = new PersonnelAnalysisBase();
            try
            {
                NodeModel nodeM = (NodeModel)nodeMo.Clone();
                List<CaseCauseModel> list = casecauseList.Where(a => a.CC_ParentID == NodeCC_ID && a.CC_NodeType == 12)
                    .ToList();
                if (list.Count > 0)
                {
                    List<CaseCauseModel> listcase = casecauseList.Where(a => a.CC_ParentID == list[0].CC_ID).ToList();

                    CaseCauseModel casecause = listcase.FirstOrDefault(a =>
                        a.XmlPath.IndexOf("姓名或名称") > -1 || a.XmlPath.IndexOf("受害人姓名") > -1 ||
                        a.XmlPath.IndexOf("丈夫姓名") > -1 || a.XmlPath.IndexOf("妻子姓名") > -1);
                    if (casecause == null)
                    {
                        casecause = listcase[0];
                    }
                    ElementConfigModel elementConfigModel =
                        Diccofig.ContainsKey(casecause.XmlPath) ? Diccofig[casecause.XmlPath] : null;

                    List<ElementSpokeName> PersonnelList = new List<ElementSpokeName>();

                    if (elementConfigModel != null)
                    {
                        string FormatType = elementConfigModel.formatType;
                        if (!string.IsNullOrEmpty(FormatType))
                        {
                            NodeModel nodemodel = new NodeModel();
                            nodemodel.ModelType = 2;
                            nodemodel.GuidID = Snowflake.Instance().GetId().ToString();
                            nodemodel.NodeID = casecause.CC_ID;
                            nodemodel.ParentGuidID = nodeM == null ? string.Empty : nodeM.GuidID;
                            nodemodel.NodePath = GetXmlPath(casecause.XmlPath);
                            nodemodel.NodeName = casecause.CC_Name;
                            nodemodel.OriginalText = OriginalText;
                            nodemodel.ElementConfigModel = Diccofig.ContainsKey(nodemodel.NodePath)
                                ? Diccofig[nodemodel.NodePath]
                                : null;
                            PersonnelList = personnelAnalysis.GetReplace(elementConfigModel, nodemodel, listNodeModel,
                                _dataContext.DataLayerAns.ElementSpokeList, nodeM);
                        }
                    }

                    foreach (ElementSpokeName spokename in PersonnelList)
                    {
                        bool pantr = false;
                        foreach (CaseCauseModel casecasue in listcase)
                        {
                            //bool isFirstLevel = false;
                            //执行节点提取前，进行先清空正则编号
                            ExpressSourceWhere.RegexCode = "";
                            NodeModel nodeModel = new NodeModel();
                            nodeModel.ModelType = 2;
                            nodeModel.GuidID = Snowflake.Instance().GetId().ToString();
                            nodeModel.NodeID = casecasue.CC_ID;
                            nodeModel.ParentGuidID = nodeM == null ? string.Empty : nodeM.GuidID;
                            nodeModel.NodePath = GetXmlPath(casecasue.XmlPath);
                            nodeModel.NodeName = casecasue.CC_Name;
                            nodeModel.OriginalText = OriginalText;
                            nodeModel.ExtOriginalText = new List<string>();
                            nodeModel.ElementConfigModel = Diccofig.ContainsKey(nodeModel.NodePath)
                                ? Diccofig[nodeModel.NodePath]
                                : null;
                            ElementConfigModel configModel = nodeModel.ElementConfigModel;
                            string formatType = configModel == null ? "" : configModel.formatType;
                            bool flog = true;
                            if (!string.IsNullOrEmpty(formatType))
                            {
                                if (!string.IsNullOrEmpty(configModel.suitDegreeID))
                                {
                                    if (configModel.suitDegreeID.IndexOf(",") > 0)
                                    {
                                        List<string> suitdegrrList = configModel.suitDegreeID.Split(',').ToList();

                                        if (suitdegrrList.FirstOrDefault(a => a == spokename.ES_SuitDrgreeID) == null)
                                        {
                                            flog = false;
                                        }
                                    }
                                    else if (configModel.suitDegreeID != null)
                                    {
                                        if (configModel.suitDegreeID != spokename.ES_SuitDrgreeID)
                                        {
                                            flog = false;
                                        }
                                    }
                                }

                                if (flog)
                                {
                                    if (formatType.ToLower() == "spokeNameToPersonName".ToLower())
                                    {
                                        nodeModel.ExtOriginalText.Add(spokename.ES_FullName);
                                    }
                                    else if (formatType == "replaceshortnametosuitpersonname")
                                    {
                                        if (nodeModel.ExtOriginalText.Count > 0)
                                        {
                                            nodeModel.ExtOriginalText[0] =
                                                ReplaceShortNameToFullName(nodeModel.ExtOriginalText[0]);
                                        }
                                    }
                                    else if (formatType.ToLower() == "spokenametopersonid")
                                    {
                                        //sp_participanttypeid
                                        nodeModel.ExtOriginalText.Add(spokename.ES_SuitDrgreeID);
                                    }
                                    else if (formatType.ToLower() == "spokenametopersonname")
                                    {
                                        nodeModel.ExtOriginalText.Add(spokename.ES_FullName);
                                    }
                                    else if (formatType.ToLower() == "spokenametosuitdegreeid")
                                    {
                                        nodeModel.ExtOriginalText.Add(spokename.ES_SuitDrgreeID);
                                    }
                                    else if (formatType.ToLower() == "sp_participanttypeid")
                                    {
                                        nodeModel.ExtOriginalText.Add(spokename.Sp_participanttypeid);
                                    }
                                    else
                                    {
                                        if (spokename.ES_ID.IndexOf("sp") > -1)
                                        {
                                            //if (dytable.DicExtTable["cs_suitparticipant"].FirstOrDefault(a => a["sp_id"] == spokename.ES_ID) != null)
                                            //{
                                            //    nodeModel.ExtOriginalText.Add(dytable.DicExtTable["cs_suitparticipant"].First(a => a["sp_id"] == spokename.ES_ID)[formatType.ToLower()]);
                                            //}
                                        }
                                    }

                                    if (!nodeModel.IsNullExtOriginalText)
                                    {
                                        nodeModel.IsNullExtOriginalText = true;
                                    }

                                    ElementConfigModel configModelnode = nodeModel.ElementConfigModel;
                                    if (!string.IsNullOrEmpty(configModelnode.sourceType))
                                    {
                                        for (int i = 0; i < nodeModel.ExtOriginalText.Count; i++)
                                        {
                                            if (nodeModel.ExtOriginalText[i] != null)
                                            {
                                                string returnvalue =
                                                    LdtJudge.DataEngine.Common.CommHelp.DictionariesConver
                                                        .GetArgumentValue(configModelnode.sourceType,
                                                            configModelnode.sourceContent,
                                                            nodeModel.ExtOriginalText[i]);
                                                if (!string.IsNullOrWhiteSpace(returnvalue))
                                                {
                                                    nodeModel.ExtOriginalText[i] = returnvalue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (flog)
                            {
                                pantr = true;
                                nodeModel.ElementCommWhere = new CommElementRegexCode()
                                {
                                    CaseType = ExpressSourceWhere.CaseType,
                                    PargarphCode = ExpressSourceWhere.PargarphCode,
                                    PargarphWhere = ExpressSourceWhere.PargarphWhere,
                                    Purpose = ExpressSourceWhere.Purpose,
                                    RegexCode = ExpressSourceWhere.RegexCode,
                                    SourceCode = ExpressSourceWhere.SourceCode,
                                    TextType = ExpressSourceWhere.TextType
                                };
                                ImplementConfig(nodeModel, listNodeModel);
                                listNodeModel.Add(nodeModel);
                            }
                        }

                        if (pantr)
                        {
                            if (elementConfigModel == null || elementConfigModel.isMultiExact != 1)
                            {
                                listNodeModel.Add(nodeM);
                            }
                        }

                        nodeM = new NodeModel();
                        nodeM.GuidID = Snowflake.Instance().GetId().ToString();
                        nodeM.ElementCommWhere = nodeMo.ElementCommWhere;
                        nodeM.ElementConfigModel = nodeMo.ElementConfigModel;
                        nodeM.ExtOriginalText = nodeMo.ExtOriginalText;
                        nodeM.IsNullExtOriginalText = nodeMo.IsNullExtOriginalText;
                        nodeM.ModelType = nodeMo.ModelType;
                        nodeM.NodeID = nodeMo.NodeID;
                        nodeM.NodeName = nodeMo.NodeName;
                        nodeM.NodePath = nodeMo.NodePath;
                        nodeM.OriginalText = nodeMo.OriginalText;
                        nodeM.ParentGuidID = nodeMo.ParentGuidID;
                        nodeM.SourcType = nodeMo.SourcType;
                        // listNodeModel.Add(nodeM);
                    }

                    ////如果是多行内容数据提取
                    if (elementConfigModel?.isMultiExact == 1)
                    {

                        NodeModel node = (NodeModel)nodeMo.Clone();
                        List<NodeModel> listmodel = ImplementConfig(node, listNodeModel);
                        listNodeModel.Add(node);

                        foreach (NodeModel nodem in listmodel)
                        {
                            LoadeNodeAttributes(nodem, NodeCC_ID, listNodeModel, OriginalText, Paragraph,
                                ExpressSourceWhere);
                            List<CaseCauseModel> lists = casecauseList
                                .Where(a => a.CC_ParentID == NodeCC_ID && a.CC_NodeType == 11).ToList();
                            foreach (CaseCauseModel casecauses in lists)
                            {
                                LoadeNodeModel(nodeMo, casecauses, listNodeModel, OriginalText, Paragraph,
                                    ExpressSourceWhere);
                            }
                        }
                    }
                    else if(elementConfigModel?.isMultiExact==2)
                    {
                        var personNodes = listNodeModel.Where(x => x.NodePath == nodeMo.NodePath).ToList();
                        if (personNodes != null && personNodes.Any())
                        {
                            foreach (var nodeItem in personNodes)
                            {
                                LoadeNodeAttributes(nodeItem, NodeCC_ID, listNodeModel, OriginalText, Paragraph,
                                        ExpressSourceWhere);
                                List<CaseCauseModel> lists = casecauseList
                                    .Where(a => a.CC_ParentID == NodeCC_ID && a.CC_NodeType == 11).ToList();
                                foreach (CaseCauseModel casecauses in lists)
                                {
                                    LoadeNodeModel(nodeItem, casecauses, listNodeModel, OriginalText, Paragraph,
                                        ExpressSourceWhere);
                                }
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _dataContext.InteractiveShow.LogShow("人员节点提取错误,错误信息" + ex.ToString(), LogMessageType.Error);
            }
        }

        /// <summary>
        /// 替换原文中的人员代称信息
        /// </summary>
        /// <param name="sprokname">人员名称</param>
        /// <returns></returns>
        public string ReplaceShortNameToFullName(string origtext)
        {
            foreach (ElementSpokeName spokename in _dataContext.DataLayerAns.ElementSpokeList)
            {
                origtext.Replace(spokename.ES_ShortName, spokename.ES_FullName);
            }

            return origtext;
        }

        /// <summary>
        /// 节点属性内容提取
        /// </summary>
        /// <param name="nodeM">节点对象数据</param>
        /// <param name="NodeCC_ID">节点对象CC_ID</param>
        /// <param name="listNodeModel">数据对象集合</param>
        /// <param name="OriginalText">原文</param>
        /// <param name="Paragraph">逻辑段集合</param>
        /// <param name="ExpressSourceWhere">条件</param>
        public void LoadeNodeAttributes(NodeModel nodeM, string NodeCC_ID, List<NodeModel> listNodeModel,
            string OriginalText, Dictionary<string, List<string>> Paragraph, CommElementRegexCode ExpressSourceWhere, bool isMl = false)
        {
            try
            {
                List<CaseCauseModel> list = casecauseList.Where(a => a.CC_ParentID == NodeCC_ID && a.CC_NodeType == 12)
                    .ToList();
                if (list.Count > 0)
                {
                    List<CaseCauseModel> listcase = casecauseList.Where(a => a.CC_ParentID == list[0].CC_ID).ToList();
                    messagelist.Add("\r\n       ====提取节点的属性内容开始====");
                    foreach (CaseCauseModel casecasue in listcase)
                    {
                        try
                        {
                            bool isFirstLevel = false;
                            //执行节点提取前，进行先清空正则编号
                            ExpressSourceWhere.RegexCode = "";
                            Dictionary<string, List<string>> listvalueNew = FactExtract_OriginalText(casecasue.CC_ID, isFirstLevel,
                                OriginalText, Paragraph, ExpressSourceWhere, out isMl);
                            if (isMl)
                            {   //通过机器学习提取
                                FactNodeMachLearnClass mlExtract = new FactNodeMachLearnClass() { _dataContext = _dataContext, casecauseList = casecauseList, Diccofig = Diccofig, uieConfig = FactNodelMLConfig };
                                var mlNodeModels = mlExtract.NodeExtractThroughML(OriginalText, nodeM.GuidID, nodeM.NodePath, nodeM.ExtValue);
                                NodeModel mlnode = mlNodeModels.FirstOrDefault(a => a.NodePath == casecasue.XmlPath);
                                if (mlnode!=null)
                                {
                                    listvalueNew = new Dictionary<string, List<string>>();
                                    listvalueNew.Add("reg", mlnode.ExtValue.ToList());
                                }
                                
                               
                            }
                            if (listvalueNew.Count > 0)
                            {

                                List<string> listvalue = listvalueNew.ContainsKey("reg") ? listvalueNew["reg"] : listvalueNew["Ai"];
                                //string value1 = string.Join("\r", listvalue);
                                //listvalue = new List<string>();
                                //listvalue.Add(value1);
                                NodeModel nodeModel = new NodeModel();
                                nodeModel.ModelType = 2;
                                nodeModel.GuidID = Snowflake.Instance().GetId().ToString();
                                nodeModel.NodeID = casecasue.CC_ID;
                                nodeModel.ParentGuidID = nodeM == null ? string.Empty : nodeM.GuidID;
                                nodeModel.NodePath = GetXmlPath(casecasue.XmlPath);
                                nodeModel.NodeName = casecasue.CC_Name;
                                nodeModel.OriginalText = OriginalText;
                                nodeModel.ExtOriginalText = listvalue;
                                nodeModel.ExtValue = listvalue;
                                if (listvalue != null && listvalue.Count > 0)
                                {
                                    nodeModel.IsNullExtOriginalText = true;
                                    for (int i = 0; i < listvalue.Count; i++)
                                    {
                                        string value = listvalue[i];
                                        messagelist.Add("       当前提取的要素属性为《" + casecasue.CC_Name +
                                                        "》提取后原文：\r\n         结果集【" + (i + 1) + "】： " + value);
                                    }
                                }
                                else
                                {
                                    messagelist.Add("       当前提取的要素属性为《" + casecasue.CC_Name + "》提取后原文：");
                                }

                                nodeModel.ElementConfigModel = Diccofig.ContainsKey(nodeModel.NodePath)
                                    ? Diccofig[nodeModel.NodePath]
                                    : null;
                                nodeModel.ElementCommWhere = (CommElementRegexCode)ExpressSourceWhere.Clone();
                                if (listvalueNew.ContainsKey("rerule"))
                                {
                                    if (listvalueNew["rerule"][0] != null)
                                    {
                                        string jsonString = listvalueNew["rerule"][0].ToString();
                                        if (!string.IsNullOrWhiteSpace(jsonString)&&JsonHelper.IsRightJson(jsonString))
                                        {
                                            JArray ja = (JArray)JsonConvert.DeserializeObject(jsonString);
                                            foreach (var jToken in ja)
                                            {
                                                JObject jo = (JObject)jToken;
                                                string index = jo["Index"].ToString();
                                                string length = jo["Length"].ToString();
                                                if (!string.IsNullOrEmpty(index))
                                                    nodeModel.OriginalLocation = index;
                                                if (!string.IsNullOrEmpty(length))
                                                    nodeModel.OriginalLocationLen = length;
                                            }
                                        }
                                    }
                                }
                                ImplementConfig(nodeModel, listNodeModel);
                                listNodeModel.Add(nodeModel);
                            }
                        }
                        catch (Exception)
                        {
                            messagelist.Add("节点属性获取错误" + casecasue.XmlPath);
                        }
                    }

                    messagelist.Add("       ====提取节点的属性内容结束====\r\n");
                }
            }
            catch (Exception ex)
            {
                messagelist.Add("       ====提取节点的属性内容错误====\r\n");
            }
        }

        /// <summary>
        /// 转换XPATH
        /// </summary>
        /// <param name="xmlpath"></param>
        /// <returns></returns>
        public string GetXmlPath(string xmlpath)
        {
            string path = xmlpath.Substring(xmlpath.IndexOf("案由要素"));
            path = "/" + path;
            return path;
        }

        /// <summary>
        /// 转字典类型
        /// </summary>
        /// <param name="nodeModel">节点信息</param>
        /// <param name="listnodemode">配置信息</param>
        /// <returns></returns>
        public List<NodeModel> ImplementConfig(NodeModel nodeModel, List<NodeModel> listnodemode)
        {
            List<NodeModel> listNodeModel = new List<NodeModel>();
            nodeModel.ExtOriginalText = nodeModel.ExtOriginalText.Where(a => a != null).ToList();
            List<NodeModel> listvalues = new List<NodeModel>();
            listvalues.Add(nodeModel);
            if (nodeModel.IsNullExtOriginalText || NodeModeParent(nodeModel, listnodemode))
            {
                #region 配置处理

                ElementConfigModel elementConfigModel = new ElementConfigModel();
                elementConfigModel = nodeModel.ElementConfigModel;

                if (elementConfigModel != null)
                {
                    #region 转字典处理

                    if (!string.IsNullOrEmpty(elementConfigModel.sourceType))
                    {
                        for (int i = 0; i < nodeModel.ExtOriginalText.Count; i++)
                        {
                            if (nodeModel.ExtOriginalText[i] != null)
                            {
                                string returnvalue =
                                    LdtJudge.DataEngine.Common.CommHelp.DictionariesConver.GetArgumentValue(
                                        elementConfigModel.sourceType, elementConfigModel.sourceContent,
                                        nodeModel.ExtOriginalText[i]);
                                if (!string.IsNullOrWhiteSpace(returnvalue))
                                {
                                    nodeModel.ExtOriginalText[i] = returnvalue;
                                    LogOut(elementConfigModel.sourceContent, returnvalue);
                                }
                            }
                        }
                    }

                    #endregion

                    #region 进行内容去重

                    if (nodeModel.ExtOriginalText.Count > 0)
                    {
                        nodeModel.ExtOriginalText = nodeModel.ExtOriginalText.Distinct().ToList();
                    }

                    #endregion

                    #region fieldType 值类型处理

                    if (!string.IsNullOrEmpty(elementConfigModel.fieldType))
                    {
                        string fieldType = elementConfigModel.fieldType;
                        for (int i = 0; i < nodeModel.ExtOriginalText.Count; i++)
                        {
                            string targetContent = string.Empty;
                            switch (fieldType)
                            {
                                //时间格式转换 天，日
                                case "datetime":
                                    Match dateMatch = Regex.Match(nodeModel.OriginalText,
                                        @"[\d零O一二三四五六七八九十]{1,4}年[\d零O一二三四五六七八九十]{1,3}月[\d零O一二三四五六七八九十]{1,3}日(?=.*?" +
                                        nodeModel.ExtOriginalText[i] + ")");
                                    string relatDateStr = dateMatch.Value; //关联的日期值
                                    targetContent = CommonFormat.FormatDateCompute(relatDateStr, nodeModel.ExtOriginalText[i]);
                                    break;
                                //转中文日期
                                case "ChineseDate":
                                    targetContent = DateTimeFormat.ConvertToDate(nodeModel.ExtOriginalText[i]);
                                    break;
                                //转换标准时间
                                case "StandardDate":
                                    targetContent = ConvertStingToDateTime.ConvertToStandardDate(nodeModel.ExtOriginalText[i]);
                                    break;
                                //转换标准时间
                                case "Standardamount":
                                    //nodeModel.ExtOriginalText[i] = BaseBianliang.SetStandardamount(nodeModel.ExtOriginalText[i]);
                                    targetContent = CommonFormat.FormatDataField(fieldType, nodeModel.ExtOriginalText[i]);
                                    break;
                                default:
                                    targetContent = CommonFormat.FormatDataField(fieldType, nodeModel.ExtOriginalText[i]);
                                    break;
                            }
                            LogOut(nodeModel.ExtOriginalText[i], targetContent);
                            nodeModel.ExtOriginalText[i] = targetContent;
                        }
                    }

                    #endregion

                    string formatType = elementConfigModel.formatType;
                    if (string.IsNullOrEmpty(formatType))
                    {
                        #region checkType数据格式转换

                        if (!string.IsNullOrEmpty(elementConfigModel.checkType))
                        {
                            string checkType = elementConfigModel.checkType;
                            //单选模式处理
                            if (checkType == "radio")
                            {
                                while (nodeModel.ExtOriginalText.Count > 1)
                                {
                                    nodeModel.ExtOriginalText.RemoveAt(1);
                                }
                            }
                            else if (checkType == "check")
                            {
                                string value = "";
                                foreach (string text in nodeModel.ExtOriginalText)
                                {
                                    value += text + ",";
                                }

                                ///清除原有的数据
                                nodeModel.ExtOriginalText.Clear();
                                nodeModel.ExtOriginalText.Add(value.TrimEnd(','));
                            }
                            else
                            {
                                if (nodeModel.ExtOriginalText.Count > 1)
                                {
                                    for (int i = 1; i < nodeModel.ExtOriginalText.Count; i++)
                                    {
                                        NodeModel nodeModelnew = new NodeModel();
                                        nodeModelnew.GuidID = Snowflake.Instance().GetId().ToString();
                                        nodeModelnew.ElementCommWhere = nodeModel.ElementCommWhere;
                                        nodeModelnew.ElementConfigModel = nodeModel.ElementConfigModel;
                                        nodeModelnew.ExtOriginalText.Add(nodeModel.ExtOriginalText[i]);
                                        nodeModelnew.IsNullExtOriginalText = nodeModel.IsNullExtOriginalText;
                                        nodeModelnew.ModelType = nodeModel.ModelType;
                                        nodeModelnew.NodeID = nodeModel.NodeID;
                                        nodeModelnew.NodeName = nodeModel.NodeName;
                                        nodeModelnew.NodePath = nodeModel.NodePath;
                                        nodeModelnew.OriginalText = nodeModel.OriginalText;
                                        nodeModelnew.ParentGuidID = nodeModel.ParentGuidID;
                                        nodeModelnew.SourcType = nodeModel.SourcType;
                                        listNodeModel.Add(nodeModelnew);
                                        listvalues.Add(nodeModelnew);
                                    }
                                }
                            }
                        }

                        #endregion
                    }
                }

                #endregion
            }
            else if (!nodeModel.IsNullExtOriginalText && nodeModel.ElementConfigModel != null)
            {
                string convertValue = LdtJudge.DataEngine.Common.CommHelp.DictionariesConver.GetArgumentValue(
                    nodeModel.ElementConfigModel.sourceType, nodeModel.ElementConfigModel.sourceContent, "");
                if (!string.IsNullOrWhiteSpace(convertValue))
                {
                    nodeModel.IsNullExtOriginalText = true;
                    nodeModel.ExtOriginalText.Add(convertValue);
                }
            }

            return listvalues;
        }

        /// <summary>
        /// 根据父级计算是否是人员节点
        /// </summary>
        /// <param name="nodeModel"></param>
        /// <returns></returns>
        public bool NodeModeParent(NodeModel nodeModel, List<NodeModel> listNodeModel)
        {
            NodeModel nodeModelP = listNodeModel.FirstOrDefault(a => a.GuidID == nodeModel.ParentGuidID);
            //|| nodeModel.ElementConfigModel.formatType== "spokeNameToPersonName"
            if (nodeModel.ElementConfigModel == null)
                return false;
            if (nodeModel.ElementConfigModel.isPersonNode == 1 || nodeModel.ElementConfigModel.formatType != null)
            {
                if (nodeModelP.IsNullExtOriginalText)
                {
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// 获取分人员带提取的原文组合 (审+原告|被告)
        /// </summary>
        /// <param name="SourceData">前置提取数据</param>
        /// <returns>按人员进行组合的原文</returns>
        public Dictionary<PersonElementEntity, string> GetGroupParseText(List<An_fayanrenduanluoxinxi> SourceData)
        {
            Dictionary<PersonElementEntity, string> groupeddic = new Dictionary<PersonElementEntity, string>();
            //DAL_An_anjianshitijuese dAL_An_Anjianshitijuese = new DAL_An_anjianshitijuese();
            int max = 0;
            var sourceDataTemp = SourceData.Where(snu => !string.IsNullOrEmpty(Convert.ToString(snu.Duanluoxuhao)));
            if (sourceDataTemp != null && sourceDataTemp.Count() > 0)
            {
                max = (int)sourceDataTemp.Max(a => a.Duanluoxuhao);
            }

            for (int i = 1; i <= max; i++)
            {
                List<An_fayanrenduanluoxinxi> grouptext = SourceData.Where(a =>
                    a.Duanluoxuhao != null && (a.Duanluoxuhao - i) > 0 && (a.Duanluoxuhao - i) < 1).ToList();
                //获取审理人员内容
                An_fayanrenduanluoxinxi textbyshen =
                    SourceData.FirstOrDefault(a => a.Duanluoxuhao != null && a.Duanluoxuhao == i);
                if (textbyshen != null)
                {
                    //如果存在审理人员信息
                    foreach (var text in grouptext)
                    {
                        var shitijuese = _dataContext.DataLayerAns.Anjianshitijueses
                            .Where(a => a.Jueseid == text.Jueseid)?.First();
                        if (shitijuese != null)
                        {
                            var anjianshiti =
                                _dataContext.DataLayerAns.Anjianshitis.FirstOrDefault(a =>
                                    a.Anjianshitiid == shitijuese.Anjianshitiid);
                            string mergedtext = textbyshen.Duanluoneirong + "\r\n" + text.Duanluoneirong;
                            groupeddic.Add(
                                new PersonElementEntity()
                                {
                                    CaseID = this.CaseID,
                                    ParseText = mergedtext,
                                    SP_ID = shitijuese.Zhuzhangfangleixing,
                                    SourceID = shitijuese.Juesesusongdiwei,
                                    SP_Name = anjianshiti.Mingcheng,
                                    SuitDegreeID = shitijuese.Juesesusongdiwei,
                                    ShortName = anjianshiti.Bieming,
                                    ParagraphCode = text.Duanluobianhao
                                }, mergedtext);
                        }
                    }
                }
                else
                {
                    //如果不存在审理人员信息
                    foreach (var text in grouptext)
                    {
                        var shitijuese = _dataContext.DataLayerAns.Anjianshitijueses
                            .Where(a => a.Jueseid == text.Jueseid)?.First();
                        if (shitijuese != null)
                        {
                            var anjianshiti =
                                _dataContext.DataLayerAns.Anjianshitis.FirstOrDefault(a =>
                                    a.Anjianshitiid == shitijuese.Anjianshitiid);
                            groupeddic.Add(
                                new PersonElementEntity()
                                {
                                    CaseID = this.CaseID,
                                    ParseText = text.Duanluoneirong,
                                    SP_ID = shitijuese.Zhuzhangfangleixing,
                                    SourceID = shitijuese.Juesesusongdiwei,
                                    SP_Name = anjianshiti.Mingcheng,
                                    SuitDegreeID = shitijuese.Juesesusongdiwei,
                                    ShortName = anjianshiti.Bieming,
                                    ParagraphCode = text.Duanluobianhao
                                }, text.Duanluoneirong);
                        }
                    }
                }
            }

            #region 优化后的段落提取方法ljx20191011###

            foreach (var text in SourceData)
            {
                if (text.Jueseid != null)
                {
                    var shitijuese = _dataContext.DataLayerAns.Anjianshitijueses.Where(a => a.Jueseid == text.Jueseid)
                        ?.First();
                    if (shitijuese != null)
                    {
                        var anjianshiti =
                            _dataContext.DataLayerAns.Anjianshitis.FirstOrDefault(a =>
                                a.Anjianshitiid == shitijuese.Anjianshitiid);
                        if (_dataContext.DataLayerAns.Fayanrenduanluoxinxis.Any(a =>
                                a.Duanluobianhao.ToLower() == text.Duanluobianhao.ToLower() &&
                                a.Jueseid == text.Jueseid))
                        {
                            //groupeddic.Add(new PersonElementEntity() { CaseID = this.CaseID, ParseText = text.OriginalText, SP_ID = text.AssertorID, SourceID = text.AssertorSuitdegreeID, SP_Name = text.AssertorName, SuitDegreeID = text.AssertorSuitdegreeID, ShortName = text.AssertorAlias, ParagraphCode = text.ParagraphCode }, text.OriginalText);
                            groupeddic.Add(
                                new PersonElementEntity()
                                {
                                    CaseID = this.CaseID,
                                    ParseText = text.Duanluoneirong,
                                    SP_ID = shitijuese.Zhuzhangfangleixing,
                                    SourceID = shitijuese.Juesesusongdiwei,
                                    SP_Name = anjianshiti.Mingcheng,
                                    SuitDegreeID = shitijuese.Juesesusongdiwei,
                                    ShortName = anjianshiti.Bieming,
                                    ParagraphCode = text.Duanluobianhao
                                }, text.Duanluoneirong);
                        }
                    }
                }
            }

            #endregion

            return groupeddic;
        }

        /// <summary>
        /// 根据诉讼地位返回用途类型
        /// 目前这里的用途只是分为原告与被告
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public ExtractType GetExtractTypeBySuitDegreeID(string p)
        {
            if (p == "89" || p == "174" || p == "4" || p == "104")
            {
                return ExtractType.yuangao;
            }
            else if (p == "90" || p == "173" || p == "1" || p == "29")
            {
                return ExtractType.beigao;
            }
            else if (p == "306")
            {
                return ExtractType.jianchajiguan;
            }
            else if (p == "164")
            {
                return ExtractType.gongsujiguan;
            }
            else if (p == "307")
            {
                return ExtractType.xingzhengjiguan;
            }
            else
            {
                return default(ExtractType);
            }
        }


        /// <summary>
        /// 将分析数据转换为数据模型保存
        /// </summary>
        /// <param name="valuePairsList">分析结果数据</param>
        public void AnalysisElementSave_new(List<NodeModelList> valuePairsList, ConfigModel amountConfig,
            CaseCauseModel casecause)
        {
            XmlUtilCommon xmlUtilCommon = new XmlUtilCommon() { dataContext = _dataContext };
            XmlDocument xmlDocument = new XmlDocument();
            XmlElement oRootNode = xmlDocument.CreateElement("root");

            DataModel dataModelRoot = new DataModel();
            dataModelRoot.ID = casecause.CC_ID;
            //dataModelRoot.XmlPath = _dataContext.DataLayerAns.CaseCausesList[0].CC_Name + "/";
            dataModelRoot.XmlPath = "案由要素/";
            dataModelRoot.State = "1";
            dataModelRoot.ParentId = "";
            dataModelRoot.sourceData = new SourceData();
            SourceData source = new SourceData();
            source.sourceList = new List<Source>();
            Source sourceD = new Source();
            sourceD.IsCheck = "1";
            sourceD.SourceCode = _dataContext.DataLayerAns.SourceCode;
            source.sourceList.Add(sourceD);
            dataModelRoot.sourceData = source;
            if (dataModelRoot.AttributesList == null)
            {
                dataModelRoot.AttributesList = new List<AttributeInfo>();
            }

            AttributeInfo causeNameAttr = new AttributeInfo();
            causeNameAttr.Name = "案由名称";
            Source causeNameSource = new Source();
            causeNameSource.IsCheck = "1";
            causeNameSource.SourceCode = _dataContext.DataLayerAns.SourceCode;
            causeNameSource.SaveValue = casecause.CC_Name;
            causeNameAttr.sourceList = new List<Source>();
            causeNameAttr.sourceList.Add(causeNameSource);
            dataModelRoot.AttributesList.Add(causeNameAttr);

            AttributeInfo causeIdAttr = new AttributeInfo();
            causeIdAttr.Name = "案由ID";
            Source causeIdSource = new Source();
            causeIdSource.IsCheck = "1";
            causeIdSource.SourceCode = _dataContext.DataLayerAns.SourceCode;
            causeIdSource.SaveValue = casecause.CC_ID;
            causeIdAttr.sourceList = new List<Source>();
            causeIdAttr.sourceList.Add(causeIdSource);
            dataModelRoot.AttributesList.Add(causeIdAttr);

            List<DataModel> dataModelLists = new List<DataModel>();
            dataModelLists.Add(dataModelRoot);
            List<XmlDocument> xmlDocumentList = new List<XmlDocument>();
            foreach (NodeModelList nodeModelList in valuePairsList)
            {
                if (nodeModelList.NodeModelKey.ElementType != ElementTypes.证据要素)
                {
                    if (nodeModelList.AfterMergeXmlNode.HasChildNodes)
                    {
                        XmlDocument xmlDocumentRoot = OpinionMain_new(nodeModelList);
                        XmlNode xmlNode = xmlDocument.ImportNode(xmlDocumentRoot.SelectSingleNode("/*"), true);
                        oRootNode.AppendChild(xmlNode);

                        List<DataModel> dataModelList =
                            DataModelConvertSourus(xmlDocumentRoot, nodeModelList.BeforeMergerListModels);
                        DataModel modelRoot = dataModelList.FirstOrDefault(a => a.ParentId == "");
                        if (modelRoot != null)
                        {
                            DataModel dataModelX = dataModelList.FirstOrDefault(a => a.ParentId == modelRoot.ID);
                            if (dataModelX != null)
                            {
                                foreach (DataModel dataModel in dataModelList.Where(a => a.ParentId == modelRoot.ID))
                                {
                                    dataModel.ParentId = dataModelRoot.ID;
                                }
                            }

                            dataModelList.Remove(modelRoot);
                        }

                        dataModelLists.AddRange(dataModelList);

                        // xmlDocumentList.Add(xmlDocumentRoot);
                    }
                }
            }

            _dataContext.InteractiveShow.LogShow("----------------进行案由要素金额内容转换---------------");
            if (amountConfig != null && !string.IsNullOrWhiteSpace(amountConfig.ConfigContent))
            {
                string message = amountConfig.ConfigContent;
                AmountModel elementcofig = XmlUtility.DeserializeToObject<AmountModel>(message);
                if (elementcofig.xmlLableModelList.FirstOrDefault(a =>
                        a.value == _dataContext.DataLayerAns.CaseCausesList[0].CC_ID) != null)
                {
                    foreach (var item in elementcofig.xmlLableModelList
                                 .FirstOrDefault(a => a.value == _dataContext.DataLayerAns.CaseCausesList[0].CC_ID)
                                 .xmlLableModelList)
                    {
                        List<DataModel> dataModelConvertList =
                            dataModelLists.Where(a => a.XmlPath == item.value)?.ToList();
                        foreach (DataModel dataModelConvert in dataModelConvertList)
                        {
                            if (dataModelConvert.AttributesList.FirstOrDefault(a => a.Name == item.attribute) != null)
                            {
                                Source sourc = dataModelConvert.AttributesList
                                    .FirstOrDefault(a => a.Name == item.attribute).sourceList
                                    .FirstOrDefault(a => a.IsCheck == "1");
                                sourc = JsonConvert.DeserializeObject<Source>(JsonConvert.SerializeObject(sourc));
                                sourc.SaveValue = sourc.ExtValue;
                                AttributeInfo attribute = new AttributeInfo();
                                if (dataModelConvert.AttributesList.FirstOrDefault(a => a.Name == item.addattrbuten) !=
                                    null)
                                {
                                    attribute = dataModelConvert.AttributesList.FirstOrDefault(a =>
                                        a.Name == item.addattrbuten);
                                    attribute.sourceList = new List<Source>();
                                    attribute.sourceList.Add(sourc);
                                }
                                else
                                {
                                    attribute.Name = item.addattrbuten;
                                    attribute.sourceList = new List<Source>();
                                    attribute.sourceList.Add(sourc);
                                    dataModelConvert.AttributesList.Add(attribute);
                                }
                            }
                        }
                    }
                }
            }

            _dataContext.InteractiveShow.LogShow("----------------进行案件要素金额内容完毕---------------");
            xmlDocument.AppendChild(oRootNode);
            EscapeNodeIndexAndBlank(xmlDocument);

            #region 上下文案由部分信息赋值

            xmlDocument = xmlUtilCommon.DataModelByXml(dataModelLists, "");
            _dataContext.DataLayerAns.ElementAnalysisResults.Add(casecause.CC_ID, xmlDocument);
            if (_dataContext.DataLayerAns.ElementAnalysisResults.ContainsKey(casecause.CC_ID))
            {
                _dataContext.DataLayerAns.ElementAnalysisResults[casecause.CC_ID] = new XmlDocument();
                _dataContext.DataLayerAns.ElementAnalysisResults[casecause.CC_ID] = xmlDocument;
            }
            else
            {
                _dataContext.DataLayerAns.ElementAnalysisResults.Add(casecause.CC_ID, xmlDocument);
            }

            if (_dataContext.DataLayerAns.ElementAnalsisDataModelResults.ContainsKey(casecause.CC_ID))
            {
                _dataContext.DataLayerAns.ElementAnalsisDataModelResults[casecause.CC_ID] = new List<DataModel>();
                _dataContext.DataLayerAns.ElementAnalsisDataModelResults[casecause.CC_ID].AddRange(dataModelLists);
            }
            else
            {
                _dataContext.DataLayerAns.ElementAnalsisDataModelResults.Add(casecause.CC_ID, dataModelLists);
            }

            if (_dataContext.DataLayerAns.AnalysisResultsDataModel == null)
                _dataContext.DataLayerAns.AnalysisResultsDataModel = new DataSoursModel();
            if (_dataContext.DataLayerAns.AnalysisResultsDataModel.dataModelList == null)
                _dataContext.DataLayerAns.AnalysisResultsDataModel.dataModelList = new List<DataModel>();
            _dataContext.DataLayerAns.AnalysisResultsDataModel.dataModelList.AddRange(dataModelLists);

            #endregion
        }

        /// <summary>
        /// 将案由要素转换为标准数据模型Datamode
        /// </summary>
        /// <param name="xmlDocument"></param>
        public List<DataModel> DataModelConvertSourus(XmlDocument xmlDocument, List<NodeModel> nodeModelList)
        {
            XmlUtilCommon xmlUtilCommon = new XmlUtilCommon() { dataContext = _dataContext };
            List<DataModel> modelList = xmlUtilCommon.NodeModelByDataModel(xmlDocument, "");
            foreach (DataModel dataModel in modelList)
            {
                Source source = dataModel.sourceData.sourceList.FirstOrDefault(a => a.IsCheck == "1");
                NodeModel nodeModel = nodeModelList.FirstOrDefault(a => a.GuidID == dataModel.ID);
                string org = "";
                if (nodeModel == null && dataModel.ID.IndexOf(",") > -1)
                {
                    nodeModel = nodeModelList.FirstOrDefault(a => a.GuidID == dataModel.ID.Split(',')[0]);
                }

                if (nodeModel != null)
                {
                    source.ParagraphCode = nodeModel?.ElementCommWhere?.PargarphCode;
                    source.OriginalText = HttpHelp.EnDataBase64(nodeModel.OriginalText);
                    if (nodeModel.ExtOriginalText != null && nodeModel.ExtOriginalText.Count > 0)
                    {
                        if (nodeModel.ExtValue != null && nodeModel.ExtValue.Count > 0)
                        {
                            source.ExtValue = nodeModel.ExtValue[0];
                        }
                        else
                        {
                            source.ExtValue = nodeModel.ExtOriginalText[0];
                        }

                        source.SaveValue = nodeModel.ExtOriginalText[0];
                    }
                    if (!string.IsNullOrEmpty(nodeModel.OriginalLocation))
                        source.OriginalLocation = nodeModel.OriginalLocation;
                    if (!string.IsNullOrEmpty(nodeModel.OriginalLocationLen))
                        source.OriginalLocationLen = nodeModel.OriginalLocationLen;
                    foreach (var attmodel in dataModel.AttributesList)
                    {
                        if (attmodel.Name != "id")
                        {
                            Source sourceatt = attmodel.sourceList.FirstOrDefault(a => a.IsCheck == "1");
                            NodeModel nodeModelAtt = nodeModelList.FirstOrDefault(a =>
                                a.ParentGuidID == nodeModel.GuidID && a.NodeName == attmodel.Name);
                            if (nodeModelAtt != null)
                            {
                                sourceatt.ParagraphCode = nodeModelAtt?.ElementCommWhere?.PargarphCode;
                                sourceatt.OriginalText = HttpHelp.EnDataBase64(nodeModelAtt.OriginalText);
                                if (nodeModelAtt.ExtValue != null && nodeModelAtt.ExtValue.Count > 0)
                                {
                                    sourceatt.ExtValue = nodeModelAtt.ExtValue[0];
                                }
                                if (!string.IsNullOrEmpty(nodeModelAtt.OriginalLocation))
                                    sourceatt.OriginalLocation = nodeModelAtt.OriginalLocation;
                                if (!string.IsNullOrEmpty(nodeModelAtt.OriginalLocationLen))
                                    sourceatt.OriginalLocationLen = nodeModelAtt.OriginalLocationLen;
                                List<string> orgList = nodeModelAtt.OriginalText
                                    .Split(new string[] { "\r" }, StringSplitOptions.None).ToList();
                                if (orgList != null && orgList.Count > 0 &&(!_dataContext.DataLayerAns.IsParagraphAnalysis.HasValue || _dataContext.DataLayerAns.IsParagraphAnalysis == false))
                                {
                                    foreach (string orgstr in orgList)
                                    {
                                        int orgstrindex = orgstr.IndexOf(sourceatt.ExtValue);
                                        if (orgstrindex > -1)
                                        {
                                            int neirongIndex = _dataContext.DataLayerAns.FengXiCanShu.Juanzongneirong
                                                .IndexOf(orgstr);
                                            if (neirongIndex > -1)
                                            {
                                                sourceatt.Location = (orgstrindex + neirongIndex).ToString();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return modelList;
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        public List<DataModel> AnalysisElementSaveXML(List<NodeModelList> valuePairsList)
        {
            XmlDocument xmlDocument = new XmlDocument();
            XmlElement oRootNode = xmlDocument.CreateElement("root");

            DataModel dataModelRoot = new DataModel();
            dataModelRoot.ID = _dataContext.DataLayerAns.ExtractCaseCausesList[0].CC_ID;
            dataModelRoot.XmlPath = "证据要素/";
            dataModelRoot.State = "1";
            dataModelRoot.ParentId = "";
            dataModelRoot.sourceData = new SourceData();
            SourceData source = new SourceData();
            source.sourceList = new List<Source>();
            Source sourceD = new Source();
            sourceD.IsCheck = "1";
            sourceD.SourceCode = _dataContext.DataLayerAns.SourceCode;
            source.sourceList.Add(sourceD);
            dataModelRoot.sourceData = source;
            List<DataModel> dataModelLists = new List<DataModel>();
            dataModelLists.Add(dataModelRoot);

            DataModel dataModelRootc = new DataModel();
            dataModelRootc.ID = Snowflake.Instance().GetId().ToString();
            dataModelRootc.XmlPath = dataModelRoot.XmlPath + "案由要素";
            dataModelRootc.State = "1";
            dataModelRootc.ParentId = dataModelRoot.ID;
            dataModelRootc.sourceData = new SourceData();
            SourceData sourceC = new SourceData();
            sourceC.sourceList = new List<Source>();
            Source sourceF = new Source();
            sourceF.IsCheck = "1";
            sourceF.SourceCode = _dataContext.DataLayerAns.SourceCode;
            sourceC.sourceList.Add(sourceD);
            dataModelRootc.sourceData = source;
            dataModelLists.Add(dataModelRootc);

            foreach (NodeModelList nodeModelList in valuePairsList)
            {
                NodeModelListByDataModel(nodeModelList.BeforeMergerListModels, dataModelLists, dataModelRootc,
                    nodeModelList.NodeModelKey, dataModelRoot.ID);
            }

            xmlDocument.AppendChild(oRootNode);
            EscapeNodeIndexAndBlank(xmlDocument);
            return dataModelLists;
        }


        public void NodeModelListByDataModel(List<NodeModel> nodeModels, List<DataModel> dataModelList,
            DataModel dataModelParent, NodeModelKey nodeModelKey, string rootid = "")
        {
            string id = "";
            if (string.IsNullOrEmpty(rootid))
            {
                id = dataModelParent.ID;
            }
            else
            {
                id = rootid;
            }

            List<NodeModel> dataList = nodeModels
                .Where(a => a.ParentGuidID == id && a.ModelType == 1 && a.IsNullExtOriginalText == true).ToList();
            foreach (NodeModel nodeModel in dataList)
            {
                Source sourceNode = new Source();
                sourceNode.ConvertCode = "";
                if (nodeModel.ElementCommWhere != null)
                {
                    sourceNode.ParagraphCode = nodeModel.ElementCommWhere.PargarphCode;
                }

                if (nodeModel.ExtOriginalText.Count > 0)
                {
                    sourceNode.SaveValue = nodeModel.ExtOriginalText[0];
                }

                sourceNode.OriginalText = HttpHelp.EnDataBase64(nodeModel.OriginalText);
                sourceNode.IsCheck = "1";
                sourceNode.SourceCode = _dataContext.DataLayerAns.SourceCode;
                DataModel dataModel = new DataModel();
                dataModel.CauseType = "1";
                dataModel.ID = nodeModel.GuidID;
                dataModel.ParentId = dataModelParent.ID;
                dataModel.State = "1";
                dataModel.XmlPath = nodeModel.NodePath;
                dataModel.sourceData = new SourceData();
                dataModel.sourceData.sourceList = new List<Source>();
                dataModel.sourceData.sourceList.Add(sourceNode);
                dataModel.AttributesList = new List<AttributeInfo>();
                List<NodeModel> dataAttList = nodeModels.Where(a =>
                    a.ParentGuidID == dataModel.ID && a.ModelType == 2 && a.IsNullExtOriginalText == true &&
                    a.ExtOriginalText.Count > 0).ToList();
                foreach (NodeModel dataAttModel in dataAttList)
                {
                    Source sourceATT = new Source();
                    sourceATT.IsCheck = "1";
                    if (dataAttModel.ElementConfigModel != null)
                    {
                        sourceATT.ConvertCode = dataAttModel.ElementConfigModel.formatType;
                    }

                    if (dataAttModel.ElementCommWhere != null)
                    {
                        sourceATT.ParagraphCode = dataAttModel.ElementCommWhere.PargarphCode;
                    }

                    sourceATT.SaveValue = dataAttModel.ExtOriginalText[0];
                    sourceATT.OriginalText = HttpHelp.EnDataBase64(dataAttModel.OriginalText);
                    sourceATT.SourceCode = _dataContext.DataLayerAns.SourceCode;
                    AttributeInfo attribute = new AttributeInfo();
                    attribute.Name = dataAttModel.NodeName;
                    attribute.sourceList = new List<Source>();
                    attribute.sourceList.Add(sourceATT);
                    dataModel.AttributesList.Add(attribute);
                }

                //添加ID
                Source sourceID = new Source();
                sourceID.SaveValue = dataModel.ID;
                sourceID.IsCheck = "1";

                AttributeInfo attributeID = new AttributeInfo();
                attributeID.Name = "id";

                attributeID.sourceList = new List<Source>();
                attributeID.sourceList.Add(sourceID);
                dataModel.AttributesList.Add(attributeID);


                dataModelList.Add(dataModel);

                NodeModelListByDataModel(nodeModels, dataModelList, dataModel, nodeModelKey);
            }
        }

        /// <summary>
        /// 主张方推导--新方式
        /// </summary>
        /// <param name="nodeModelList">结果集</param>
        public XmlDocument OpinionMain_new(NodeModelList nodeModelList)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(nodeModelList.AfterMergeXmlNode.OuterXml);
            string selectXmlpath = "";
            if (nodeModelList.NodeModelKey.ElementType == ElementTypes.事实要素)
            {
                //selectXmlpath = _dataContext.DataLayerAns.CaseCausesList[0].CC_Name + "/事实要素";
                selectXmlpath = "案由要素/事实要素";
            }
            else if (nodeModelList.NodeModelKey.ElementType == ElementTypes.诉请要素)
            {
                //selectXmlpath = _dataContext.DataLayerAns.CaseCausesList[0].CC_Name + "/诉请要素";
                selectXmlpath = "案由要素/诉请要素";
            }
            else if (nodeModelList.NodeModelKey.ElementType == ElementTypes.无争议要素)
            {
                //selectXmlpath = _dataContext.DataLayerAns.CaseCausesList[0].CC_Name + "/诉请要素";
                selectXmlpath = "案由要素/事实要素";
            }
            else if (nodeModelList.NodeModelKey.ElementType == ElementTypes.结果要素)
            {
                //selectXmlpath = _dataContext.DataLayerAns.CaseCausesList[0].CC_Name + "/诉请要素";
                selectXmlpath = "案由要素/结果要素";
            }

            if (!string.IsNullOrEmpty(selectXmlpath))
            {
                XmlNode xmlNode = xmlDocument.SelectSingleNode(selectXmlpath + "/主张方");
                if (xmlNode == null)
                {
                    XmlElement rootElement = xmlDocument.CreateElement("主张方");
                    XmlAttribute xmlAttribute = xmlDocument.CreateAttribute("主张方姓名或名称");
                    xmlAttribute.Value = nodeModelList.NodeModelKey.SP_Name;
                    XmlAttribute xmlAttributes = xmlDocument.CreateAttribute("主张方诉讼地位");
                    xmlAttributes.Value = nodeModelList.NodeModelKey.SP_SuitdegreeID;
                    rootElement.Attributes.Append(xmlAttribute);
                    rootElement.Attributes.Append(xmlAttributes);

                    XmlNode xmlNodeRoot = xmlDocument.SelectSingleNode(selectXmlpath);
                    if (xmlNodeRoot != null)
                    {
                        xmlNodeRoot.AppendChild(rootElement);
                    }
                }
                else
                {
                    if (xmlNode.Attributes["主张方姓名或名称"] != null)
                    {
                        xmlNode.Attributes["主张方姓名或名称"].Value = nodeModelList.NodeModelKey.SP_Name;
                    }
                    else
                    {
                        XmlAttribute xmlAttribute = xmlDocument.CreateAttribute("主张方姓名或名称");
                        xmlAttribute.Value = nodeModelList.NodeModelKey.SP_Name;
                        xmlNode.Attributes.Append(xmlAttribute);
                    }

                    if (xmlNode.Attributes["主张方诉讼地位"] != null)
                    {
                        xmlNode.Attributes["主张方诉讼地位"].Value = nodeModelList.NodeModelKey.SP_SuitdegreeID;
                    }
                    else
                    {
                        XmlAttribute xmlAttribute = xmlDocument.CreateAttribute("主张方诉讼地位");
                        xmlAttribute.Value = nodeModelList.NodeModelKey.SP_SuitdegreeID;
                        xmlNode.Attributes.Append(xmlAttribute);
                    }
                }
            }

            return xmlDocument;
        }

        /// <summary>
        /// 数据转换函数日志输出方法
        /// </summary>
        /// <param name="sourceContent">转换前内容</param>
        /// <param name="targetContent">转换后内容</param>
        private void LogOut(string sourceContent, string targetContent)
        {
            // _dataContext.InteractiveShow.LogShow("数据转换：转换前为：" + sourceContent + " 转换后为：" + targetContent, LogMessageType.Info);
        }
    }
}